using System;
using System.Globalization;
using System.Speech.Synthesis;
using SG.Ling.AutoTranslator.NLP;

namespace SG.Ling.AutoTranslator.TTS
{
    public class VoiceDisplay : IEquatable<VoiceDisplay>, IEquatable<InstalledVoice>
    {
        private readonly string _name;
        private readonly CultureInfo _culture;

        public VoiceDisplay(InstalledVoice voice)
        {
            _name = voice.VoiceInfo.Name;
            _culture = voice.VoiceInfo.Culture;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as VoiceDisplay) || Equals(obj as InstalledVoice);
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public bool Equals(VoiceDisplay other)
        {
            if (other == null)
            {
                return false;
            }

            return other.Name == Name;
        }

        public CultureInfo Culture { get { return _culture; } }
        public string Name { get { return _name; } }

        public bool Equals(InstalledVoice other)
        {
            if (other == null)
            {
                return false;
            }

            return other.VoiceInfo.Name == Name;
        }

        public override string ToString()
        {
            return string.Format("{0} - {1}", Name, new CultureInfoDisplay(Culture));
        }
    }
}